home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_lib.arc / FLCREATE.C < prev    next >
Text File  |  1990-08-09  |  3KB  |  80 lines

  1. /**
  2. *
  3. *  Name         flcreate -- Create a file
  4. *
  5. *  Synopsis     ercode = flcreate(pfile,phandle,attrib);
  6. *               int  ercode       Returned DOS error code
  7. *               char *pfile       File path name to be opened
  8. *               int  *phandle     Returned DOS file handle
  9. *               int  attrib       file attribute
  10. *
  11. *  Description  The specified file name is created if it does not exist,
  12. *               or truncates an existing file to zero length.  The file
  13. *               is opened for reading and writing, and it can be accessed
  14. *               by using the returned handle number.  Note that an
  15. *               existing read only file cannot be created (it cannot be
  16. *               truncated) nor can volume labels or subdirectories be
  17. *               created using FLCREATE.  The possible file attributes are:
  18. *
  19. *                0 - General, no attribute
  20. *                1 - Read only (may not be opened for writing)
  21. *                2 - Hidden file
  22. *                4 - System file
  23. *                8 - Volumne label
  24. *               16 - Subdirectory
  25. *               32 - Archive flag (file changed since last backed up)
  26. *
  27. *               File attributes may be combined by adding the attribute codes.
  28. *
  29. *  Returns      ercode            DOS 2.0 function error code
  30. *               phandle           File handle of the created file. If an
  31. *                                 error is encountered, -1 is returned.
  32. *
  33. *  Version      1.1  (C)Copyright Blaise Computing Inc.  1983, 1984
  34. *
  35. **/
  36. #include <compiler.h>
  37.  
  38. #define utbyword(a,b)   (((a)<<8)|((b)&0x00ff))  /* a is high, b low   */
  39.  
  40. struct dreg
  41. {
  42.   unsigned ax,bx,cx,dx,si,di,ds,es;
  43. };
  44. #define DOSREG  struct dreg
  45.  
  46. int flcreate(pfile,phandle,attrib)
  47. char *pfile;
  48. int  *phandle,attrib;
  49. {
  50.  
  51.     DOSREG dos_reg;
  52.     int    ercode,utinit(),dos();
  53. #if CI201A & LDATA
  54.     unsigned long ptrtoabs();
  55. #endif
  56.  
  57.     utinit(&dos_reg);                  /* Initialize the registers     */
  58.     dos_reg.ax = utbyword(0x3c,0);     /* Function call 3C             */
  59.     dos_reg.cx = utbyword(0,attrib);
  60. #if LDATA
  61. #if CI201A
  62.     dos_reg.ds = (unsigned)((ptrtoabs(pfile) & 0xffff0L) >> 4L);
  63.     dos_reg.dx = (unsigned)(ptrtoabs(pfile) & 0xfL);
  64. #else
  65.     dos_reg.ds = (unsigned)(((long)(pfile) & 0xffff0L) >> 4L);
  66.     dos_reg.dx = (unsigned)((long)(pfile) & 0xfL);
  67. #endif
  68. #else
  69.     dos_reg.dx = (unsigned)pfile;
  70. #endif
  71.     ercode     = dos(&dos_reg);
  72.     if (ercode == 0)
  73.        *phandle = (int)dos_reg.ax;
  74.     else
  75.        *phandle = -1;
  76.  
  77.     return(ercode);
  78.  
  79. }
  80.